package com.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @author wzm
 * @create 2033-10-16 11:33
 * project_name:javaweb2308
 */
@Component
//@Aspect //切面类
@Slf4j
//@Order(2)
public class AdviceTypes03 {
    //通知  一个通知就是一个方法 通过切入点表达式指定需要增强的方法

    //前置通知
    @Before("execution(* com.aop.service.*.*())")
    public void before(){
        log.info("03前置通知before...");
    }

    //环绕通知
    @Around("execution(* com.aop.service.*.*())")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("03环绕通知方法前...");

        //环绕通知必须执行目标对象的原始方法
        Object proceed = proceedingJoinPoint.proceed();

        log.info("03环绕通知方法后...");

        //一定要返回
        return proceed;
    }

    //后置通知（有无异常都执行）
    @After("execution(* com.aop.service.*.*())")
    public void after(){
        log.info("03后置通知after...");
    }

    //返回后通知(程序在执行返回后无异常执行)
    @AfterReturning("execution(* com.aop.service.*.*())")
    public void afterReturning(){
        log.info("03返回后通知AfterReturning...");
    }

    //异常后通知
    @AfterThrowing("execution(* com.aop.service.*.*())")
    public void afterThrowing(){
        log.info("03异常后通知afterThrowing...");
    }

}
